//
//  LWMainViewController.swift
//  ios8-01 weibo框架搭建
//
//  Created by blue on 16/2/26.
//  Copyright © 2016年 honeywell. All rights reserved.
//

import UIKit

class LWMainViewController: UITabBarController, LWMainTabBarDelegate {
    
    
    override func viewDidLoad() {
        
        //调用父类的方法
        super.viewDidLoad()
        
        //取消tabbar文字渲染－这种方式只适合文字和图片是同一种颜色的情况
        //self.tabBar.tintColor = UIColor.orangeColor()
        
        
        //拿出tabbar
        //tabBar = UITabBar()
        let mainTabBar = LWMainTabBar()
        
        //4.设置代理
        mainTabBar.composeDelegate = self
        
        
        //这个的作用是什么？？？
        setValue(mainTabBar, forKey:"tabBar")
        
        
        
        //添加子控制器
      self.addChildViewControllers()
        
    }
    
    
    //5.实现代理方法
    func  mainTabBarComposeClick() {
        
        print("在主控制器中有点击代理有响应")
        
    }
    
    func  addChildViewControllers(){
        
        //设置子控制器
        
        //主页
        let homeVc = LWHomeController()
        //homeVc.view.backgroundColor = UIColor.redColor()
        self.addChildViewController(homeVc, title: "主页", imageName: "tabbar_home")
        
        //消息
        let messageVc = LWMessageController()
        //messageVc.view.backgroundColor = UIColor.blueColor()
        self.addChildViewController(messageVc, title: "消息", imageName: "tabbar_message_center")
        
        //加号控制器
        let composeVc = UIViewController()
        //composeVc.view.backgroundColor = UIColor.grayColor()
        self.addChildViewController(composeVc, title: "", imageName: "")

        
        //发现
        let discoverVc = LWDiscoverController()
        //discoverVc.view.backgroundColor = UIColor.greenColor()
        self.addChildViewController(discoverVc, title: "发现", imageName: "tabbar_discover")

        
        //我
        let profileVc = LWProfileController()
        //profileVc.view.backgroundColor = UIColor.orangeColor()
        self.addChildViewController(profileVc, title: "我", imageName: "tabbar_profile")

        
        
       
        
        
        
    }
    
    // 添加子控制器，并且设置标题和图片
    func  addChildViewController(childController: UIViewController,
        title: String, imageName: String ) {
        
        childController.title = title
          
            //设置文本的渲染模式
            let dict = [NSForegroundColorAttributeName:UIColor.orangeColor()]
            childController.tabBarItem.setTitleTextAttributes(dict, forState: UIControlState.Selected)
            
            //设置图片的渲染模式==子控制器被选中时的图片tabbar_home_highlighted
           //childController.tabBarItem.image = UIImage(named: imageName)
            childController.tabBarItem.image = UIImage(named: imageName)
            
            let  selecteImg = imageName + "_highlighted"
            
            childController.tabBarItem.selectedImage = UIImage(named:selecteImg)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            
            
        self.addChildViewController(childController)
            
            //包装导航控制器
            let nav = UINavigationController(rootViewController: childController)
            
           //把包装完的控制器添加到tabbar控制器上
            self.addChildViewController(nav)
            
        
    }

}
